#define _CRT_SECURE_NO_WARNINGS 1
#include "my_string.h"
size_t my_strlen(const char* arr)
{
	assert(arr);
	int a = 0;
	while (*arr++)
	{
		a++;
	}
	return a;
}


char* my_strcpy(char* arr1, const char* arr2)
{
	assert(arr1 && arr2);
	const char* ret = arr1;
	while (*arr1++ = *arr2++);
	return ret;
}


int my_strcmp(const char* arr1, const char* arr2)
{
	assert(arr1 && arr2);
	while (*arr1 == *arr2)
	{
		if (*arr1 == '\0')
		{
			return 0;
		}
		arr1++;
		arr2++;
	}
	if (*arr1 > *arr2)
	{
		return 1;
	}
	else
	{
		return -1;
	}
}

char* my_strcat(char* arr1, const char* arr2)
{
	char* ret = arr1;
	while (*arr1)
	{
		arr1++;
	}
	while (*arr1++ = *arr2++);
	return ret;
}

char* my_strstr(const char* arr1, const char* arr2)
{
	assert(arr1 && arr2);
	if (*arr2 == '\0')
	{
		return arr1;
	}
	char* a1 = NULL;
	char* a2 = NULL;
	char* cp = arr1;
	while (*cp)
	{
		a1 = cp;
		a2 = arr2;
		while (*a1 != '\0' && *a2 != '\0' && *a1 == *a2)
		{
			if (*a1 == *a2)
			{
				a2++;
			}
			a1++;
		}
		if (*a2 == '\0')
		{
			return cp;
		}
		cp++;
	}
	return NULL;
}


void* my_memcpy(void* arr1, const void* arr2,size_t n)
{
	assert(arr1 && arr2);
	void* str = arr1;
	while (n--)
	{
		*(char*)arr1 = *(char*)arr2;
		(char*)arr1 = (char*)arr1 + 1;
		(char*)arr2 = (char*)arr2 + 1;
	}
	return str;
}

void* my_memmove(void* arr1, const void* arr2, size_t n)
{
	assert(arr1 && arr2);
	void* ret = arr1;
	if (arr1 > arr2)
	{
		while (n--)
		{
			*(char*)arr1 = *(char*)arr2;
			arr1 = (char*)arr1 + 1;
			arr2 = (char*)arr2 + 1;
		}
	}
	else
	{
		while (n--)
		{
			*((char*)arr1 + n) = *((char*)arr2 + n);
		}
	}
	return ret;
}










